﻿Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.IO
Imports System.Windows.Forms
Imports System.Workflow.ComponentModel

Namespace System.Workflow.ComponentModel.Design
    Public MustInherit Class StructuredCompositeActivityDesigner
        Inherits CompositeActivityDesigner
        ' Methods
        Protected Sub New()
        End Sub

        Private Function CanDrop(ByVal e As ActivityDragEventArgs) As Integer
            If (e.Activities.Count = 0) Then
                Return -1
            End If
            Dim dropPoint As New Point(e.X, e.Y)
            Dim connector As Integer = -1
            Dim dropTargets As Rectangle() = Me.GetDropTargets(dropPoint)
            Dim i As Integer
            For i = 0 To dropTargets.Length - 1
                If dropTargets(i).Contains(dropPoint) Then
                    connector = i
                    Exit For
                End If
            Next i
            If ((connector >= 0) AndAlso Not Me.CanInsertActivities(New ConnectorHitTestInfo(Me, HitTestLocations.Designer, connector), e.Activities)) Then
                connector = -1
            End If
            Dim flag As Boolean = ((e.KeyState And 8) = 8)
            If (((connector >= 0) AndAlso Not flag) AndAlso ((e.AllowedEffect And DragDropEffects.Move) = DragDropEffects.Move)) Then
                Dim moveLocation As New ConnectorHitTestInfo(Me, HitTestLocations.Designer, connector)
                Dim activity As Activity
                For Each activity In e.Activities
                    If (Not activity.Site Is Nothing) Then
                        Dim designer As ActivityDesigner = ActivityDesigner.GetDesigner(activity)
                        If (((designer Is Nothing) OrElse (designer.ParentDesigner Is Nothing)) OrElse Not designer.ParentDesigner.CanMoveActivities(moveLocation, New List([Of] Activity)(New Activity() { activity }).AsReadOnly)) Then
                            Return -1
                        End If
                    End If
                Next
            End If
            Return connector
        End Function

        Public Overrides Function CanInsertActivities(ByVal insertLocation As HitTestInfo, ByVal activitiesToInsert As ReadOnlyCollection([Of] Activity)) As Boolean
            If (insertLocation Is Nothing) Then
                Throw New ArgumentNullException("insertLocation")
            End If
            If (activitiesToInsert Is Nothing) Then
                Throw New ArgumentNullException("activitiesToInsert")
            End If
            Dim designer As ActivityDesigner = If((Not Me.ActiveView Is Nothing), Me.ActiveView.AssociatedDesigner, Nothing)
            If (Not designer Is Me) Then
                Return False
            End If
            Dim activityTypes As IList([Of] Type) = SecondaryViewProvider.GetActivityTypes(Me)
            Dim activity As Activity
            For Each activity In activitiesToInsert
                If (activity Is Nothing) Then
                    Throw New ArgumentException("activitiesToInsert", SR.GetString("Error_CollectionHasNullEntry"))
                End If
                If activityTypes.Contains(activity.GetType) Then
                    Return False
                End If
            Next
            Return MyBase.CanInsertActivities(Me.GetUpdatedLocation(insertLocation), activitiesToInsert)
        End Function

        Public Overrides Function CanRemoveActivities(ByVal activitiesToRemove As ReadOnlyCollection([Of] Activity)) As Boolean
            If (activitiesToRemove Is Nothing) Then
                Throw New ArgumentNullException("activitiesToRemove")
            End If
            Return MyBase.CanRemoveActivities(activitiesToRemove)
        End Function

        Private Function CheckDragEffect(ByVal e As ActivityDragEventArgs) As DragDropEffects
            If (e.Activities.Count = 0) Then
                Return DragDropEffects.None
            End If
            If (Me.CurrentDropTarget >= 0) Then
                If (((e.KeyState And 8) = 8) AndAlso ((e.AllowedEffect And DragDropEffects.Copy) = DragDropEffects.Copy)) Then
                    Return DragDropEffects.Copy
                End If
                If ((e.AllowedEffect And DragDropEffects.Move) = DragDropEffects.Move) Then
                    Return DragDropEffects.Move
                End If
            End If
            Return e.Effect
        End Function

        Protected Sub DrawConnectors(ByVal graphics As Graphics, ByVal pen As Pen, ByVal points As Point(), ByVal startCap As LineAnchor, ByVal endCap As LineAnchor)
            Dim empty As Size = Size.Empty
            Dim maxCapSize As Size = Size.Empty
            Dim designerTheme As CompositeDesignerTheme = [TryCast](MyBase.DesignerTheme,CompositeDesignerTheme)
            If (Not designerTheme Is Nothing) Then
                empty = New Size((designerTheme.ConnectorSize.Width / 3), (designerTheme.ConnectorSize.Height / 3))
                maxCapSize = designerTheme.ConnectorSize
            End If
            ActivityDesignerPaint.DrawConnectors(graphics, pen, points, empty, maxCapSize, startCap, endCap)
        End Sub

        Public Overrides Sub EnsureVisibleContainedDesigner(ByVal containedDesigner As ActivityDesigner)
            If (containedDesigner Is Nothing) Then
                Throw New ArgumentNullException("containedDesigner")
            End If
            Me.Expanded = True
            Dim activeDesigner As ActivityDesigner = Me.ActiveDesigner
            If ((Not containedDesigner Is activeDesigner) AndAlso (Not containedDesigner Is Me)) Then
                Dim view As DesignerView = Nothing
                Dim validatedViews As ReadOnlyCollection([Of] DesignerView) = Me.ValidatedViews
                Dim view2 As DesignerView
                For Each view2 In validatedViews
                    If (containedDesigner Is view2.AssociatedDesigner) Then
                        view = view2
                        Exit For
                    End If
                Next
                If (view Is Nothing) Then
                    view = validatedViews.Item(0)
                End If
                Me.ActiveView = view
                Dim designer2 As CompositeActivityDesigner = [TryCast](Me.ActiveDesigner,CompositeActivityDesigner)
                If (Not designer2 Is Nothing) Then
                    If (Not designer2 Is Me) Then
                        designer2.EnsureVisibleContainedDesigner(containedDesigner)
                    Else
                        MyBase.EnsureVisibleContainedDesigner(containedDesigner)
                    End If
                End If
            End If
        End Sub

        Protected Overridable Function GetDropTargets(ByVal dropPoint As Point) As Rectangle()
            Return New Rectangle() { MyBase.Bounds }
        End Function

        Protected Overridable Function GetInnerConnections(ByVal edges As DesignerEdges) As ReadOnlyCollection([Of] Point)
            Dim list As New List([Of] Point)(Me.GetConnections(edges))
            If ((list.Count > 0) AndAlso ((edges And DesignerEdges.Top) > DesignerEdges.None)) Then
                Dim point As Point = list.Item(0)
                Dim point2 As Point = list.Item(0)
                list.Item(0) = New Point(point.X, (point2.Y + Me.TitleHeight))
            End If
            Return list.AsReadOnly
        End Function

        Public Overrides Function GetNextSelectableObject(ByVal current As Object, ByVal direction As DesignerNavigationDirection) As Object
            Dim nextSelectableObject As Object = Nothing
            Dim activeDesigner As ActivityDesigner = Me.ActiveDesigner
            If (activeDesigner Is Nothing) Then
                Return nextSelectableObject
            End If
            If (Not activeDesigner Is Me) Then
                If ((Not current Is activeDesigner.Activity) AndAlso TypeOf activeDesigner Is CompositeActivityDesigner) Then
                    nextSelectableObject = DirectCast(activeDesigner, CompositeActivityDesigner).GetNextSelectableObject(current, direction)
                End If
                Return nextSelectableObject
            End If
            Return MyBase.GetNextSelectableObject(current, direction)
        End Function

        Private Function GetUpdatedLocation(ByVal location As HitTestInfo) As HitTestInfo
            Dim num As Integer = 0
            Dim view As DesignerView
            For Each view In Me.Views
                If (((Not view.AssociatedDesigner Is Nothing) AndAlso (Not Me Is view.AssociatedDesigner)) AndAlso Helpers.IsActivityLocked(view.AssociatedDesigner.Activity)) Then
                    num += 1
                End If
            Next
            Return New ConnectorHitTestInfo(Me, location.HitLocation, (num + location.MapToIndex))
        End Function

        Protected Overrides Sub Initialize(ByVal activity As Activity)
            MyBase.Initialize(activity)
            Me.ActiveView = Me.ValidatedViews.Item(0)
        End Sub

        Public Overrides Sub InsertActivities(ByVal insertLocation As HitTestInfo, ByVal activitiesToInsert As ReadOnlyCollection([Of] Activity))
            If (insertLocation Is Nothing) Then
                Throw New ArgumentNullException("insertLocation")
            End If
            If (activitiesToInsert Is Nothing) Then
                Throw New ArgumentNullException("activitiesToInsert")
            End If
            MyBase.InsertActivities(Me.GetUpdatedLocation(insertLocation), activitiesToInsert)
        End Sub

        Protected Overrides Sub LoadViewState(ByVal reader As BinaryReader)
            If (reader Is Nothing) Then
                Throw New ArgumentNullException("reader")
            End If
            Dim str As String = reader.ReadString
            If ((Not str Is Nothing) AndAlso str.Equals("ActiveView", StringComparison.Ordinal)) Then
                Dim num As Integer = reader.ReadInt32
                Dim validatedViews As ReadOnlyCollection([Of] DesignerView) = Me.ValidatedViews
                If ((num <> -1) AndAlso (num < validatedViews.Count)) Then
                    Me.ActiveView = validatedViews.Item(num)
                End If
            End If
            MyBase.LoadViewState(reader)
        End Sub

        Public Overrides Sub MoveActivities(ByVal moveLocation As HitTestInfo, ByVal activitiesToMove As ReadOnlyCollection([Of] Activity))
            If (moveLocation Is Nothing) Then
                Throw New ArgumentNullException("moveLocation")
            End If
            If (activitiesToMove Is Nothing) Then
                Throw New ArgumentNullException("activitiesToMove")
            End If
            MyBase.MoveActivities(Me.GetUpdatedLocation(moveLocation), activitiesToMove)
        End Sub

        Protected Overrides Sub OnActivityChanged(ByVal e As ActivityChangedEventArgs)
            Dim views As ReadOnlyCollection([Of] DesignerView) = SecondaryViewProvider.GetViews(Me)
            Dim onlys2 As ReadOnlyCollection([Of] DesignerView) = Me.Views
            If (views.Count <> onlys2.Count) Then
                Me.views = Nothing
                MyBase.PerformLayout
            End If
            MyBase.OnActivityChanged(e)
        End Sub

        Protected Overrides Sub OnContainedActivitiesChanging(ByVal listChangeArgs As ActivityCollectionChangeEventArgs)
            MyBase.OnContainedActivitiesChanging(listChangeArgs)
            If ((listChangeArgs.Action = ActivityCollectionChangeAction.Remove) AndAlso (Not listChangeArgs.RemovedItems.Item(0) Is Nothing)) Then
                Dim activeDesigner As ActivityDesigner = Me.ActiveDesigner
                If ((Not activeDesigner Is Nothing) AndAlso (listChangeArgs.RemovedItems.Item(0) Is activeDesigner.Activity)) Then
                    Me.ActiveView = Me.ValidatedViews.Item(0)
                End If
                SecondaryViewProvider.OnViewRemoved(Me, listChangeArgs.RemovedItems.Item(0).GetType)
            End If
        End Sub

        Protected Overrides Sub OnDragDrop(ByVal e As ActivityDragEventArgs)
            MyBase.OnDragDrop(e)
            If (((e.KeyState And 8) = 8) AndAlso ((e.AllowedEffect And DragDropEffects.Copy) = DragDropEffects.Copy)) Then
                e.Effect = DragDropEffects.Copy
            ElseIf ((e.AllowedEffect And DragDropEffects.Move) = DragDropEffects.Move) Then
                e.Effect = DragDropEffects.Move
            End If
            Try 
                CompositeActivityDesigner.InsertActivities(Me, New ConnectorHitTestInfo(Me, HitTestLocations.Designer, Me.CurrentDropTarget), e.Activities, SR.GetString("DragDropActivities"))
            Finally
                Me.CurrentDropTarget = -1
            End Try
        End Sub

        Protected Overrides Sub OnDragEnter(ByVal e As ActivityDragEventArgs)
            MyBase.OnDragEnter(e)
            Me.CurrentDropTarget = Me.CanDrop(e)
            e.Effect = Me.CheckDragEffect(e)
            e.DragImageSnapPoint = Me.SnapInToDropTarget(e)
        End Sub

        Protected Overrides Sub OnDragLeave()
            MyBase.OnDragLeave
            Me.CurrentDropTarget = -1
        End Sub

        Protected Overrides Sub OnDragOver(ByVal e As ActivityDragEventArgs)
            MyBase.OnDragOver(e)
            Me.CurrentDropTarget = Me.CanDrop(e)
            e.Effect = Me.CheckDragEffect(e)
            e.DragImageSnapPoint = Me.SnapInToDropTarget(e)
        End Sub

        Protected Overrides Sub OnLayoutPosition(ByVal e As ActivityDesignerLayoutEventArgs)
            If (e Is Nothing) Then
                Throw New ArgumentNullException("e")
            End If
            MyBase.OnLayoutPosition(e)
            If Me.Expanded Then
                Dim activeDesigner As ActivityDesigner = Me.ActiveDesigner
                If ((Not activeDesigner Is Nothing) AndAlso (Not activeDesigner Is Me)) Then
                    Dim location As Point = Me.Location
                    location.X = (location.X + ((Me.Size.Width - activeDesigner.Size.Width) / 2))
                    location.Y = (location.Y + e.AmbientTheme.SelectionSize.Height)
                    activeDesigner.Location = location
                End If
                Dim titleHeight As Integer = Me.TitleHeight
                Dim designer2 As ActivityDesigner
                For Each designer2 In Me.ContainedDesigners
                    designer2.Location = New Point(designer2.Location.X, (designer2.Location.Y + titleHeight))
                Next
            End If
        End Sub

        Protected Overrides Function OnLayoutSize(ByVal e As ActivityDesignerLayoutEventArgs) As Size
            Dim size As Size = MyBase.OnLayoutSize(e)
            If Me.Expanded Then
                Dim activeDesigner As ActivityDesigner = Me.ActiveDesigner
                If ((Not activeDesigner Is Nothing) AndAlso (Not activeDesigner Is Me)) Then
                    size.Width = Math.Max(size.Width, activeDesigner.Size.Width)
                    size.Height = (size.Height + activeDesigner.Size.Height)
                    size.Width = (size.Width + (2 * e.AmbientTheme.SelectionSize.Width))
                    size.Width = (size.Width + (3 * e.AmbientTheme.Margin.Width))
                    size.Height = (size.Height + e.AmbientTheme.Margin.Height)
                    size.Height = (size.Height + (2 * e.AmbientTheme.SelectionSize.Height))
                End If
            End If
            Return size
        End Function

        Friend Overrides Sub OnPaintContainedDesigners(ByVal e As ActivityDesignerPaintEventArgs)
            Dim flag As Boolean = False
            Dim designer As ActivityDesigner
            For Each designer In Me.ContainedDesigners
                Dim bounds As Rectangle = designer.Bounds
                If e.ViewPort.IntersectsWith(bounds) Then
                    flag = True
                    DirectCast(designer, IWorkflowDesignerMessageSink).OnPaint(New PaintEventArgs(e.Graphics, e.ViewPort), e.ViewPort)
                ElseIf flag Then
                    Exit For
                End If
            Next
        End Sub

        Private Sub OnPaletteClosed(ByVal sender As Object, ByVal e As EventArgs)
            MyBase.Invalidate(MyBase.DesignerSmartTag.GetBounds(Me, True))
        End Sub

        Protected Overrides Sub OnShowSmartTagVerbs(ByVal smartTagPoint As Point)
            If (Me.itemPalette Is Nothing) Then
                Me.itemPalette = New ItemPalette
                AddHandler Me.itemPalette.Closed, New EventHandler(AddressOf Me.OnPaletteClosed)
                AddHandler Me.itemPalette.SelectionChanged, New SelectionChangeEventHandler([Of] SelectionChangeEventArgs)(AddressOf Me.OnSmartAction)
            End If
            Me.itemPalette.SetFont(WorkflowTheme.CurrentTheme.AmbientTheme.Font)
            Me.itemPalette.Items.Clear
            Dim verb As ActivityDesignerVerb
            For Each verb In Me.SmartTagVerbs
                Dim image As Image = [TryCast](verb.Properties.Item(DesignerUserDataKeys.Image),Image)
                Dim item As New ItemInfo(verb.Id, image, verb.Text)
                item.UserData.Item(DesignerUserDataKeys.DesignerVerb) = verb
                Me.itemPalette.Items.Add(item)
            Next
            Dim location As Point = MyBase.PointToScreen(smartTagPoint)
            Me.itemPalette.Show(location)
        End Sub

        Private Sub OnSmartAction(ByVal sender As Object, ByVal e As SelectionChangeEventArgs)
            Dim currentItem As ItemInfo = e.CurrentItem
            If (Not currentItem Is Nothing) Then
                Dim verb As ActivityDesignerVerb = [TryCast](currentItem.UserData.Item(DesignerUserDataKeys.DesignerVerb),ActivityDesignerVerb)
                If (Not verb Is Nothing) Then
                    verb.Invoke
                End If
            End If
        End Sub

        Private Sub OnSmartTagVerb(ByVal sender As Object, ByVal e As EventArgs)
            Dim verb As ActivityDesignerVerb = [TryCast](sender,ActivityDesignerVerb)
            Dim view As DesignerView = [TryCast](verb.Properties.Item(DesignerUserDataKeys.DesignerView),DesignerView)
            If (Not view Is Nothing) Then
                Me.ActiveView = view
                If (Me.Expanded AndAlso (Not view.AssociatedDesigner Is Nothing)) Then
                    Dim service As ISelectionService = [TryCast](MyBase.GetService(GetType(ISelectionService)),ISelectionService)
                    If (Not service Is Nothing) Then
                        service.SetSelectedComponents(New Object() { view.AssociatedDesigner.Activity }, SelectionTypes.Replace)
                    End If
                End If
            End If
        End Sub

        Private Sub OnSmartTagVerbStatus(ByVal sender As Object, ByVal e As EventArgs)
            Dim verb As ActivityDesignerVerb = [TryCast](sender,ActivityDesignerVerb)
            Dim view As DesignerView = [TryCast](verb.Properties.Item(DesignerUserDataKeys.DesignerView),DesignerView)
            If (Not view Is Nothing) Then
                verb.Checked = (view Is Me.ActiveView)
            End If
        End Sub

        Protected Overridable Sub OnViewChanged(ByVal view As DesignerView)
            MyBase.PerformLayout
        End Sub

        Protected Overrides Sub SaveViewState(ByVal writer As BinaryWriter)
            If (writer Is Nothing) Then
                Throw New ArgumentNullException("writer")
            End If
            Dim list As New List([Of] DesignerView)(Me.ValidatedViews)
            writer.Write("ActiveView")
            writer.Write(list.IndexOf(Me.activeView))
            MyBase.SaveViewState(writer)
        End Sub

        Private Function SnapInToDropTarget(ByVal e As ActivityDragEventArgs) As Point
            If (Me.CurrentDropTarget >= 0) Then
                Dim dropTargets As Rectangle() = Me.GetDropTargets(New Point(e.X, e.Y))
                If (Me.CurrentDropTarget < dropTargets.Length) Then
                    Dim rectangle As Rectangle = dropTargets(Me.CurrentDropTarget)
                    Return New Point((rectangle.Left + (rectangle.Width / 2)), (rectangle.Top + (rectangle.Height / 2)))
                End If
            End If
            Return Point.Empty
        End Function


        ' Properties
        Friend ReadOnly Property ActiveDesigner As ActivityDesigner
            Get
                If (Not Me.ActiveView Is Nothing) Then
                    Return Me.ActiveView.AssociatedDesigner
                End If
                Return Nothing
            End Get
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public Property ActiveView As DesignerView
            Get
                If (Me.activeView Is Nothing) Then
                    Me.activeView = Me.ValidatedViews.Item(0)
                End If
                Return Me.activeView
            End Get
            Set(ByVal value As DesignerView)
                If ((Not Me.activeView Is value) AndAlso (Not value Is Nothing)) Then
                    Dim activeView As DesignerView = Me.activeView
                    Me.activeView = value
                    value.OnActivate
                    If (value.AssociatedDesigner Is Nothing) Then
                        value.OnDeactivate
                        Me.activeView = activeView
                    Else
                        If (Not activeView Is Nothing) Then
                            activeView.OnDeactivate
                        End If
                        Me.OnViewChanged(Me.activeView)
                        DesignerHelpers.RefreshDesignerActions(MyBase.Activity.Site)
                        MyBase.RefreshDesignerVerbs
                    End If
                End If
            End Set
        End Property

        Public Overrides ReadOnly Property ContainedDesigners As ReadOnlyCollection([Of] ActivityDesigner)
            Get
                Dim list As New List([Of] ActivityDesigner)
                Dim activeDesigner As ActivityDesigner = Me.ActiveDesigner
                If (Not activeDesigner Is Nothing) Then
                    If (activeDesigner Is Me) Then
                        list.AddRange(MyBase.ContainedDesigners)
                        Dim list2 As New List([Of] ActivityDesigner)
                        Dim designersFromSupportedViews As IList([Of] ActivityDesigner) = Me.DesignersFromSupportedViews
                        Dim designer2 As ActivityDesigner
                        For Each designer2 In list
                            Dim flag As Boolean = Helpers.IsAlternateFlowActivity(designer2.Activity)
                            If (designersFromSupportedViews.Contains(designer2) OrElse flag) Then
                                list2.Add(designer2)
                            End If
                        Next
                        Dim designer3 As ActivityDesigner
                        For Each designer3 In list2
                            list.Remove(designer3)
                        Next
                    Else
                        list.Add(activeDesigner)
                    End If
                End If
                Return list.AsReadOnly
            End Get
        End Property

        Protected Overridable Property CurrentDropTarget As Integer
            Get
                Return Me.currentDropTarget
            End Get
            Set(ByVal value As Integer)
                Me.currentDropTarget = value
                MyBase.Invalidate
            End Set
        End Property

        Private ReadOnly Property DesignersFromSupportedViews As IList([Of] ActivityDesigner)
            Get
                Dim list As New List([Of] ActivityDesigner)
                Dim view As DesignerView
                For Each view In Me.ValidatedViews
                    Dim associatedDesigner As ActivityDesigner = view.AssociatedDesigner
                    If (Not associatedDesigner Is Nothing) Then
                        list.Add(associatedDesigner)
                    End If
                Next
                Return list.AsReadOnly
            End Get
        End Property

        Public Overrides ReadOnly Property FirstSelectableObject As Object
            Get
                Dim activeDesigner As ActivityDesigner = Me.ActiveDesigner
                If ((Not activeDesigner Is Nothing) AndAlso (Not activeDesigner Is Me)) Then
                    Return activeDesigner.Activity
                End If
                Return MyBase.FirstSelectableObject
            End Get
        End Property

        Public Overrides ReadOnly Property LastSelectableObject As Object
            Get
                Dim activeDesigner As ActivityDesigner = Me.ActiveDesigner
                If (((Not activeDesigner Is Nothing) AndAlso (Not activeDesigner Is Me)) AndAlso TypeOf activeDesigner Is CompositeActivityDesigner) Then
                    Return DirectCast(activeDesigner, CompositeActivityDesigner).LastSelectableObject
                End If
                Return MyBase.LastSelectableObject
            End Get
        End Property

        Public Overrides ReadOnly Property MinimumSize As Size
            Get
                Dim minimumSize As Size = MyBase.MinimumSize
                Dim activeDesigner As ActivityDesigner = Me.ActiveDesigner
                If (((Not activeDesigner Is Nothing) AndAlso (Not activeDesigner Is Me)) AndAlso Me.Expanded) Then
                    minimumSize.Width = Math.Max(minimumSize.Width, 160)
                    minimumSize.Height = Math.Max(minimumSize.Height, 160)
                End If
                Return minimumSize
            End Get
        End Property

        Protected Overrides ReadOnly Property ShowSmartTag As Boolean
            Get
                Return ((Not String.IsNullOrEmpty(Me.Text) AndAlso Not Me.TextRectangle.Size.IsEmpty) AndAlso (Me.Views.Count > 1))
            End Get
        End Property

        Protected Overrides ReadOnly Property SmartTagVerbs As ReadOnlyCollection([Of] ActivityDesignerVerb)
            Get
                Dim list As New List([Of] ActivityDesignerVerb)(MyBase.SmartTagVerbs)
                If (Me.Views.Count > 1) Then
                    Dim i As Integer
                    For i = 0 To Me.Views.Count - 1
                        Dim view As DesignerView = Me.Views.Item(i)
                        Dim item As New ActivityDesignerVerb(Me, DesignerVerbGroup.Actions, view.Text, New EventHandler(AddressOf Me.OnSmartTagVerb), New EventHandler(AddressOf Me.OnSmartTagVerbStatus))
                        item.Properties.Item(DesignerUserDataKeys.DesignerView) = view
                        item.Properties.Item(DesignerUserDataKeys.Image) = view.Image
                        list.Add(item)
                    Next i
                End If
                Return list.AsReadOnly
            End Get
        End Property

        Friend Overrides Property SmartTagVisible As Boolean
            Get
                Return (((Not Me.itemPalette Is Nothing) AndAlso Me.itemPalette.IsVisible) OrElse MyBase.SmartTagVisible)
            End Get
            Set(ByVal value As Boolean)
                MyBase.SmartTagVisible = value
            End Set
        End Property

        Private ReadOnly Property ValidatedViews As ReadOnlyCollection([Of] DesignerView)
            Get
                Dim views As ReadOnlyCollection([Of] DesignerView) = Me.Views
                If (views.Count = 0) Then
                    Throw New InvalidOperationException(DR.GetString("Error_MultiviewSequentialActivityDesigner", New Object(0  - 1) {}))
                End If
                Return views
            End Get
        End Property

        Public Overridable ReadOnly Property Views As ReadOnlyCollection([Of] DesignerView)
            Get
                If (Me.views Is Nothing) Then
                    Me.views = New List([Of] DesignerView)
                    Me.views.AddRange(SecondaryViewProvider.GetViews(Me))
                End If
                Return Me.views.AsReadOnly
            End Get
        End Property


        ' Fields
        Private activeView As DesignerView
        Private currentDropTarget As Integer = -1
        Private itemPalette As ItemPalette
        Private views As List([Of] DesignerView)
    End Class
End Namespace

